# GetFirstChildControl() GetLastChildControl()
# GetPreviousSiblingControl() GetNextSiblingControl()
# GetParentControl() GetChildren()
# uia.SetGlobalSearchTimeout(0) GetRuntimeId() uia.SetGlobalSearchTimeout(10.0)
# ClassName BoundingRectangle.height()
import sys
import datetime


def getJavaPos():
    import uiautomation as auto

    # 设置全局搜索时间
    # auto.uiautomation.SetGlobalSearchTimeout(5)

    javapos = auto.WindowControl(ClassName='SWT_Window0')

    # 如果没有找到对应的程序
    if not javapos.Exists(0, 0):
        return False

    head = {}
    # 左上角内容
    item = javapos.TextControl(Name='成交价').GetParentControl().GetChildren()
    head['spmc'] = item[2].GetValuePattern().Value
    head['cjje'] = item[1].Name
    head['yfje'] = item[4].Name

    # 右上角上内容
    item = javapos.TextControl(Name='总金额').GetParentControl().GetChildren()
    head['zje'] = item[1].Name
    head['dlx'] = item[3].Name
    head['zjs'] = item[5].Name
    head['zzk'] = item[7].Name

    # 右上角中内容
    item = javapos.TextControl(Name='收银机').GetParentControl().GetChildren()
    head['syjh'] = item[1].Name
    head['syyh'] = item[3].Name

    # 右上角下内容
    item = javapos.TextControl(Name='顾客卡').GetParentControl().GetChildren()
    head['hykh'] = item[1].Name
    print(head)

    # 商品明细
    items = [c for c, d in auto.WalkControl(javapos) if isinstance(c, auto.ListControl)]    
    items = items[0].GetChildren()
    # items = javapos.GroupControl(Name='商品明细').GetFirstChildControl().GetChildren()
    num = 0
    title = []
    sales = []
    for v in items:
        if v.Name == '垂直滚动条':
            continue
        vals = v.GetChildren()
        row = []
        for i in vals:
            if num == 0:
                title.append(i.Name)
            else:
                row.append(i.Name)
        if num > 0:
            sales.append(row)
        num += 1

    return head, title, sales


temp = getJavaPos()

print(temp)

